<?php

namespace app\common\model;

use think\model\relation\BelongsTo;
use think\model\relation\HasMany;

class Goods extends BaseModel
{
    public function brand(): BelongsTo
    {
        return $this->belongsTo(GoodsBrand::class,'brand_id','id');
    }

    public function spec(): HasMany
    {
        return $this->hasMany(GoodsSpec::class, 'goods_id', 'id');
    }

    public function cate(): BelongsTo
    {
        return $this->belongsTo(GoodsCate::class, 'cate_id', 'id');
    }

    // 获取商品信息
    public function getGoodsInfo($id){
        return $this->where('id',$id)->with(['brand'])->find();
    }
}